﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Inicio.Entities;
using System.Windows.Forms;


namespace Inicio.Core
{
    public class Connection
    { 
        //public static string conec = @"Data Source=C:\Users\Fabricio.duarte.ACCENDO\Procesos\gedea\AgendaSQL\DB\Agenda.sdf";// "Data Source=.;Initial Catalog=AgendaDB;Integrated Security=SSPI";
        //public static string conec = @"Data Source=C:\Users\Fabri\Documents\Visual Studio 2010\Projects\Compartidos\gedea\AgendaSQL\DB\Agenda.sdf";
        public static string conec = @"Data Source= " + string.Format(@"{0}\DB\Agenda.sdf", Application.StartupPath);

        public List<Country> LoadCountrys()
        {
            Core.Repositories.CountryRepositorie conn = new Repositories.CountryRepositorie();
            return conn.LoadCountrys(conec);
        }

        public List<Province> LoadProvinces(int countryId)
        {
            Core.Repositories.ProvinceRepositorie conn = new Repositories.ProvinceRepositorie();
            return conn.LoadProvinces(conec, countryId);
        }

        public List<Currency> LoadCurrency()
        {
            Core.Repositories.CurrencyRepositorie conn = new Repositories.CurrencyRepositorie();
            return conn.LoadCurrency(conec);
        }

        public List<Enterprise> LoadLenders()
        {
            Core.Repositories.LenderRepositorie conn = new Repositories.LenderRepositorie();
            return conn.LoadLenders(conec);
        }

        public List<Rendering> LoadWorkTypes(int lenderId)
        {
            Core.Repositories.WorkTypeRepositorie conn = new Repositories.WorkTypeRepositorie();
            return conn.LoadWorkTypes(lenderId, conec);
        }

        public List<Obra> LoadObras()
        {
            Core.Repositories.ObraRepositorie conn = new Repositories.ObraRepositorie();
            return conn.LoadObras(conec);

            //List<Obra> obras = new List<Obra>();

            //SqlConnection cn = new SqlConnection(conec);
            //cn.Open();
            //SqlCommand cmd = new SqlCommand(
            //    "SELECT id, obraName FROM Obra ORDER BY obraName ASC", cn);
            //SqlDataReader reader = cmd.ExecuteReader();
            //while (reader.Read())
            //{
            //    obras.Add(new Obra((int)reader["id"], reader["obraName"].ToString()));
            //}
            //reader.Close();
            //cmd.Dispose();
            //if (cn != null) cn.Close();
            //return obras;
        }

        public void NewObra(Obra obra, List<Spout> spouts)
        {
            Core.Repositories.ObraRepositorie conn = new Repositories.ObraRepositorie();
            conn.NewObra(obra, conec, spouts);

        }

    }

    
}
